package com.sky.controller.admin;

import com.sky.constant.MessageConstant;
import com.sky.dto.SetmealDTO;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.common.SetmealService;
import com.sky.vo.SetmealVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 套餐请求处理类
 * @author zgp
 * @version V1.0
 * @date 2025-01-15 9:48
 */
@RestController
@RequestMapping("/admin/setmeal")
@Api(tags = "套餐管理")
@Slf4j
public class SetmealController {
    @Autowired
    private SetmealService setmealService;

    @GetMapping("/page")
    @ApiOperation("套餐条件分页查询")
    public Result<PageResult<SetmealVO>> pageList(SetmealPageQueryDTO pageQueryDTO){
        log.info("套餐条件分页查询，setmealPageQueryDTO：{}", pageQueryDTO);
        return Result.success(setmealService.getPageList(pageQueryDTO));
    }

    @PostMapping
    @ApiOperation("新增套餐")
    public Result<String> addSetmeal(@RequestBody SetmealDTO setmealDTO){
        setmealService.addSetmeal(setmealDTO);
        return Result.success(MessageConstant.ADD_SUCCESS);
    }

    @DeleteMapping
    @ApiOperation("套餐批量删除")
    public Result<String> deleteSetmeals(@RequestParam("ids") List<Long> ids){
        log.info("套餐批量删除，ids：{}", ids);
        setmealService.deleteOfBatch(ids);
        return Result.success(MessageConstant.DELETE_SUCCESS);
    }

    @PutMapping
    @ApiOperation("套餐修改")
    public Result<String> modifySetmeal(@RequestBody SetmealDTO setmealDTO){
        log.info("套餐修改，setmealDTO：{}", setmealDTO);
        setmealService.updateById(setmealDTO);
        return Result.success(MessageConstant.UPDATE_SUCCESS);
    }

    @GetMapping("/{id}")
    @ApiOperation("根据id查询套餐")
    public Result<SetmealVO> getSetmealById(@PathVariable Long id){
        log.info("根据id查询套餐，id：{}", id);
        return Result.success(setmealService.getSetmealById(id));
    }

    @PostMapping("/status/{status}")
    @ApiOperation("套餐启售/停售")
    public Result<String> enableOrDisableSetmean(@PathVariable Integer status, Long id){
        log.info("套餐启售/停售，id：{}，status：{}", id, status);
        setmealService.enableOrDisableSetmeal(status, id);
        return Result.success(MessageConstant.UPDATE_SUCCESS);
    }

}
